<template>
	<view>
		<tm-message ref="toast"></tm-message>
    <view :style="{ height: '200rpx' }"></view>
		<view>
			<tm-button v-if="isAgreement" icon="icon-weixin" open-type="getPhoneNumber"
				@getphonenumber="onLogin"  block :round="24" :icon-size="32" :height="100" :font-size="32">微信登录</tm-button>
			<tm-button v-else icon="icon-weixin" @click="clickNotAgreement"
                 block :round="24" :icon-size="32" :height="100" :font-size="32">微信登录</tm-button>
		</view>

	</view>
</template>

<script>
	import {
		mapActions
	} from 'vuex';
	import * as api from '../api.js'
	export default {
		props: {
			isAgreement: {
				type: Boolean,
				default: false
			}
		},
		methods: {
			...mapActions(['wxLogin']),
			// 未勾选时事件
			clickNotAgreement() {
				this.$refs.toast.show({model:'quest',label:'请先阅读并同意协议条款'})
			},
			// 微信登录
			onLogin(data) {
				if (this.isAgreement) {
					if (!data.detail.code) return
					uni.showLoading({
						title: '登录中...'
					});
					this.wxLogin(data)
				} else {
          this.$refs.toast.show({model:'error',label:'请填写正确的手机号'})
				}

			}
		}
	}
</script>

<style>
</style>
